package com.ruoyi.product.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.product.domain.SpuSkuVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.product.mapper.ProductSpuMapper;
import com.ruoyi.product.domain.ProductSpu;
import com.ruoyi.product.service.IProductSpuService;

/**
 * 商品SPUService业务层处理
 * 
 * @author liuhuizhong
 * @date 2025-08-07
 */
@Service
public class ProductSpuServiceImpl implements IProductSpuService 
{
    @Autowired
    private ProductSpuMapper productSpuMapper;

    /**
     * 查询商品SPU
     * 
     * @param id 商品SPU主键
     * @return 商品SPU
     */
    @Override
    public ProductSpu selectProductSpuById(Long id)
    {
        return productSpuMapper.selectProductSpuById(id);
    }

    @Override
    public List<SpuSkuVo> getSpuWithSkuBySpuId(Long spuId) {
        return productSpuMapper.selectSpuWithSkuBySpuId(spuId);
    }

    /**
     * 查询商品SPU列表
     * 
     * @param productSpu 商品SPU
     * @return 商品SPU
     */
    @Override
    public List<ProductSpu> selectProductSpuList(ProductSpu productSpu)
    {
        return productSpuMapper.selectProductSpuList(productSpu);
    }

    /**
     * 新增商品SPU
     * 
     * @param productSpu 商品SPU
     * @return 结果
     */
    @Override
    public int insertProductSpu(ProductSpu productSpu)
    {
        productSpu.setCreatedAt(DateUtils.getNowDate());
        return productSpuMapper.insertProductSpu(productSpu);
    }

    /**
     * 修改商品SPU
     * 
     * @param productSpu 商品SPU
     * @return 结果
     */
    @Override
    public int updateProductSpu(ProductSpu productSpu)
    {
        productSpu.setUpdatedAt(DateUtils.getNowDate());
        return productSpuMapper.updateProductSpu(productSpu);
    }

    /**
     * 批量删除商品SPU
     * 
     * @param ids 需要删除的商品SPU主键
     * @return 结果
     */
    @Override
    public int deleteProductSpuByIds(Long[] ids)
    {
        return productSpuMapper.deleteProductSpuByIds(ids);
    }

    /**
     * 删除商品SPU信息
     * 
     * @param id 商品SPU主键
     * @return 结果
     */
    @Override
    public int deleteProductSpuById(Long id)
    {
        return productSpuMapper.deleteProductSpuById(id);
    }
}
